package com.alien.smartmusicplayer.textproject;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import me.imid.swipebacklayout.lib.SwipeBackLayout;
import me.imid.swipebacklayout.lib.app.SwipeBackActivity;

/**
 * Created by Alien_yuan on 2015/11/23.
 */
public class LockScreenView extends SwipeBackActivity {

    private TextView textView;
    private MyBroadcastReceiver myBroadcastReceiver;
    private LinearLayout linearLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d("alien", "LockScreenService:LockScreenView-" + getResources().getDisplayMetrics().widthPixels);
        setContentView(R.layout.lockscreen_view);
        getSwipeBackLayout().setEdgeSize(500);

        linearLayout = (LinearLayout)findViewById(R.id.screen_parent);
        //这句话最最最重要，能实现在锁屏上面显示activity
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

        textView = ((TextView) findViewById(R.id.timer));
        myBroadcastReceiver = new MyBroadcastReceiver();
        registerReceiver(myBroadcastReceiver, new IntentFilter("aaa"));

        getSwipeBackLayout().setEdgeTrackingEnabled(SwipeBackLayout.EDGE_LEFT);
    }

    @Override
    protected void onDestroy() {

        unregisterReceiver(myBroadcastReceiver);
        super.onDestroy();
    }

    private class MyBroadcastReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            textView.setText(intent.getIntExtra("time", -2));
            Log.d("alien", "LockScreenService:timer-" + intent.getIntExtra("time", -2));
        }
    }

}
